
#include <BRender>
#include <BMaterial>

#include "DebugCamera.h"


DebugCamera::DebugCamera()
{

}
DebugCamera::~DebugCamera()
{

}

void DebugCamera::render(BRender& render)
{
	BState state;
	state.setLighting(false);
	state.setLineSmooth(true);
	state.setLineWidth(1);
	render.setState(&state);

	BFrustum frustum = this->frustum();
	BVector v0 = frustum.v0();
	BVector v1 = frustum.v1();
	BVector v2 = frustum.v2();
	BVector v3 = frustum.v3();

	BVector v4 = frustum.v4();
	BVector v5 = frustum.v5();
	BVector v6 = frustum.v6();
	BVector v7 = frustum.v7();

	const BPlane& pfar = frustum.farPlane();
	const BPlane& pnear = frustum.nearPlane();
	const BPlane& pleft = frustum.leftPlane();
	const BPlane& pright = frustum.rightPlane();
	const BPlane& ptop = frustum.topPlane();
	const BPlane& pbottom = frustum.bottomPlane();

	BVector origin;

	render.setColor(BColor(0, 0, 255) * 0.5);
	render.drawQuad(v0, v1, v2, v3);

	render.setColor(BColor(1, 1, 0) * 0.5);
	render.drawTriangle(v0, v1, origin);
	render.drawTriangle(v1, v2, origin);
	render.drawTriangle(v2, v3, origin);
	render.drawTriangle(v3, v0, origin);

	render.setColor(BColor(0, 1, 0));
	render.drawLine(v0, origin);
	render.drawLine(v1, origin);
	render.drawLine(v2, origin);
	render.drawLine(v3, origin);

	BVector v;
	render.setColor(BColor(1, 0, 0));

	v = v0 + (v1-v0)/2;
	render.drawLine(v, v + pleft.normal() * 20);
	v = v1 + (v2-v1)/2;
	render.drawLine(v, v + pbottom.normal() * 20);
	v = v2 + (v3-v2)/2;
	render.drawLine(v, v + pright.normal() * 20);
	v = v3 + (v0-v3)/2;
	render.drawLine(v, v + ptop.normal() * 20);
	v = v0 + (v2-v0)/2;
	render.drawLine(v, v + pfar.normal() * 20);
}
